package org.linlinjava.litemall.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.linlinjava.litemall.db.dao.NoticeMapper;
import org.linlinjava.litemall.db.models.Notice;
import org.linlinjava.litemall.db.service.NoticeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
        implements NoticeService {

    @Override
    public IPage<Notice> querySelective(String title, String content, Integer pageNo, Integer pageSize) {
        Page<Notice> page = new Page<>(pageNo, pageSize);
        QueryWrapper<Notice> query = new QueryWrapper<>();
        query.like(!StringUtils.isEmpty(title), "title", title);
        query.like(!StringUtils.isEmpty(content), "content", content);

        return baseMapper.selectPage(page, query);
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        this.baseMapper.deleteBatchIds(ids);
    }
}
